home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 8 / CU Amiga Magazine's Super CD-ROM 08 (1997)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1997-03].iso / c / makeindex < prev    next >
Text File  |  1996-11-01  |  6KB  |  179 lines

  1. /* MakeIndex
  2.     Hacked by Andy Macklin to produce a sort of index of doc/guide files.
  3.     My version of grep uses the following syntax...
  4.     usage: grep [-[[AB] ]<num>] [-[CEFGVchilnqsvwx]] [-[ef]] <expr> [<files...>]
  5.  
  6.         Requirements:   grep
  7.                         sort
  8.                         copy
  9.                         searchguide (optional)
  10.                         same syntax as buildindex  (optional)
  11.  
  12. */
  13.  
  14. buildidx='Y' /*Change to 'Y' for an all in one script ;) */
  15. SGUIDE='N'   /*Change to 'Y' for an automatic search button in the docs guide file */
  16.  
  17. address command
  18.  
  19. Volume = left(pragma('D'),pos(':',pragma('D')))
  20.  
  21. /* defines and such */
  22.         /* GREP CALL */
  23. GREPCALL = "grep"
  24.         /* GREP HELP CALL */
  25. GREPHELP = "grep -h"
  26.         /* Where's the CUCD index? */
  27. IDXLOC = Volume'CUCD.index'
  28.         /* Where's the finished guide to go to?*/
  29. outfile = Volume'Docs.guide'
  30.         /* Path to MultiView */
  31. MView = Volume'Utilities/MultiView'
  32.         /* Extensions to search for */
  33. Extensions = 'guide|doc|dok|txt|text|asc|man|readme'
  34.  
  35. if buildidx='Y' then do
  36.     /* NB the column format is important for the sort fuction later */
  37.     'delete >NIL:' outfile    /* Otherwise the guide will contain a reference to itself */
  38.     'list' Volume 'all files pat=~(#?.info) lformat "%-33N%P%N" to' IDXLOC
  39.     end
  40.  
  41. grepfile = "t:grepoutput." || Pragma("i")
  42. agfile = "t:grepguide." || Pragma("i")
  43. CR      = d2c(10)
  44. TAB     = d2c(9)
  45.  
  46. /* setup the output file - we need this first so we can show errors in it */
  47. IF Open(agfp,agfile,'w') = 0 THEN DO
  48.         SAY "Couldn't create amigaguide file ("||agfile||")"
  49.         EXIT 20
  50.         END
  51.  
  52. call writeln(agfp,'@DATABASE "CD docs"')
  53. call writeln(agfp,'@REMARK created by Andys MakeIndex v2 :)')
  54. call writeln(agfp,'')
  55. call writeln(agfp,'@NODE Main "DOCS & GUIDES"')
  56. call writeln(agfp,'')
  57.  
  58. /* Put a search button (needs searchguide in the CDs path) */
  59. if SGUIDE='Y' then do
  60. call writeln(agfp,'@{" Search " SYSTEM "RUN SearchGuide '||substr(outfile,pos(':',outfile)+1)||'" }')
  61. call writeln(agfp,'')
  62. end
  63.  
  64. SIGNAL ON FAILURE
  65. ADDRESS COMMAND
  66. 'delete >NIL:' grepfile
  67. do until Extensions = ''
  68.     parse var Extensions ext '|' Extensions
  69.     GREPCALL '-F .'ext IDXLOC '>>' grepfile
  70.     end
  71. 'rename' grepfile ' to ' grepfile||'.old'
  72. 'sort' grepfile||'.old' grepfile 'colstart 37'
  73. SIGNAL OFF FAILURE
  74.  
  75. IF Open(grepfp,grepfile,'r') = 0 THEN DO
  76.         CALL HandleError("Couldn't open grep output file ("||grepfile||")","")
  77.         END
  78.  
  79. /*************************************************************************
  80. **  Format of Grep output
  81. **  =====================
  82. **
  83. **HTMLit!.guide                 CUCD4:Magazine/WiredWorld/HTMLit!/HTMLit!.guide
  84. **DemosOfTheWorld.guide         CUCD4:CUCD/Demos/DemosOfTheWorld/DemosOfTheWorld.guide
  85. **mc12.guide                    CUCD4:CUCD/Demos/Malevolent_Creations/mc12.guide
  86. **iml-Feb71.guide               CUCD4:CUCD/Graphics/Imagine/iml-Feb71.guide
  87. **Dust.guide                    CUCD4:CUCD/Graphics/Imagine/Dust/Docs/Dust.guide
  88. **DustEnglish.guide             CUCD4:CUCD/Graphics/Imagine/Dust/Docs/DustEnglish.guide
  89. **IM_Organizer.guide            CUCD4:CUCD/Graphics/Imagine/IM_Organiser/IM_Organizer.guide
  90. **TextureStudio.guide           CUCD4:CUCD/Graphics/Imagine/TextureStudio/Docs/TextureStudio.guide
  91. **ncFTPevents.guide             CUCD4:CUCD/Online/ThorStuff/Programs/ncFTPevents/Thor/docs/ncFTPevents.guide
  92. **
  93. ****************************************************************************/
  94.  
  95. line = ReadLn(grepfp)
  96. IF EOF(grepfp) THEN DO
  97.         call close(grepfp)
  98.         say 'No files found'
  99.         exit 10
  100.         END
  101.  
  102.  
  103.         CALL Pragma('W','n')            /* turn off dos requesters */
  104.  
  105. DO WHILE ~EOF(grepfp)
  106.         /* START BY LOOKING FOR FILENAMES */
  107.         currentfile = Strip(Left(line,Length(Word(line,1))),"B")
  108.         location = strip(right(line,length(line)-length(word(line,1))),"B")
  109.         if right(currentfile,5) ='guide' then
  110.         do
  111.             node='/main'
  112.             action='link "'
  113.         end
  114.         else
  115.         do
  116.             node=''
  117.             action='system "'MView' '
  118.         end
  119.         endif
  120.         call writeln(agfp,'@{" 'currentfile left('',33-length(currentfile))' "' action||location||node'" }   'substr(location,pos(':',location)+1))
  121.         line = ReadLn(grepfp)
  122.                 END
  123.  
  124. call WriteLn(agfp,'@ENDNODE')
  125.  
  126. call Close(grepfp)
  127. call Close(agfp)
  128.  
  129.        CALL Pragma('W','w')            /* turn dos requesters back on */
  130.  
  131. address command
  132. 'copy' agfile outfile
  133. 'delete >NIL:' grepfile
  134. 'delete >NIL:' grepfile||'.old'
  135. 'delete >NIL:' agfile
  136.  
  137. EXIT
  138.  
  139. FAILURE:
  140. ERROR:
  141.         errRC = RC
  142.         CALL Close(grepfp)
  143.         CALL HandleError("Grep Failure:"|| CR || "    " || FullCommand ,grepfile)
  144.         EXIT
  145.  
  146. /***************************************************/
  147. HandleError: PROCEDURE EXPOSE agfp grepfile agfile grephelp
  148.  
  149.         ErrorText = arg(1)
  150.         ErrorFile = arg(2)
  151.  
  152.         call writeln(agfp,'-=-=-=-=-=-=-=-=-=  E R R O R  =-=-=-=-=-=-=-=-=-')
  153.         call writeln(agfp,ErrorText)
  154.         call writeln(agfp,' ')
  155.  
  156.         IF (ErrorFile~="" & Exists(ErrorFile)) THEN DO
  157.                 call writeln(agfp,"Response:")
  158.                 ADDRESS COMMAND GREPHELP '>>'ErrorFile
  159.                 Open('errorfp',ErrorFile,'r')
  160.                 DO WHILE ~EOF('errorfp')
  161.                         call writeln(agfp,"    " || ReadLn('errorfp'))
  162.                         END
  163.                 call close('errorfp')
  164.                 END
  165.  
  166.         call writeln(agfp,"")
  167.         call writeln(agfp,"Current Path:")
  168.         call writeln(agfp,"    "||Pragma("D"))
  169.         call writeln(agfp,'@ENDNODE')
  170.  
  171.         call close(agfp)
  172.  
  173.         IF Exists(grepfile) THEN Delete(grepfile)
  174.         Delete(agfile)
  175.  
  176.         EXIT 20
  177. RETURN
  178.  
  179.